****APPENDIX TABLE D3-D5****

cd "$main_dir/output/tables/appendix_d"

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant data
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)
egen birth_state_gen = group(birth_state generation)

//--------------------------------------------------------
//Create Table D3
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc if trust_others!=., absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize trust_fed_govt
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc if trust_others!=., absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d3.doc, replace dec(3) nocons addtext(State FE, Yes, ///
														    Survey Year FE, Yes, ///
															Generation FE, Yes, ///
														    State FE x Survey Year FE, No) keep(zwgrowth_rate_1) 																

//Column 2															
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc if trust_others!=., absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize trust_fed_govt
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc if trust_others!=., absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d3.doc, append dec(3) nocons addtext(State FE, No, ///
														    Survey Year FE, No, ///
															Generation FE, Yes, ///
														    State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1) 													

//Column 3															
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc if trust_others!=., absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize trust_govt_index
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc if trust_others!=., absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d3.doc, append dec(3) nocons addtext(State FE, Yes, ///
														    Survey Year FE, Yes, ///
															Generation FE, Yes, ///
														    State FE x Survey Year FE, No) keep(zwgrowth_rate_1) 																

//Column 4															
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc if trust_others!=., absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize trust_govt_index
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc if trust_others!=., absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d3.doc, append dec(3) nocons addtext(State FE, No, ///
														    Survey Year FE, No, ///
															Generation FE, Yes, ///
														    State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1) 

//--------------------------------------------------------
//Create Table D4
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
standardize trust_fed_govt
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, replace dec(3) nocons addtext(State FE, Yes, ///
														    Survey Year FE, Yes, ///
														    State FE x Survey Year FE, No, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 

//Column 2															
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize trust_fed_govt
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, append dec(3) nocons addtext(State FE, No, ///
														    Survey Year FE, No, ///
														    State FE x Survey Year FE, Yes, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 

//Column 3															
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
standardize trust_govt_index
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, append dec(3) nocons addtext(State FE, Yes, ///
														    Survey Year FE, Yes, ///
														    State FE x Survey Year FE, No, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 

//Column 4															
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize trust_govt_index
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, append dec(3) nocons addtext(State FE, No, ///
														    Survey Year FE, No, ///
														    State FE x Survey Year FE, Yes, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 															

//Column 5															
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
standardize trust_others
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, append dec(3) nocons addtext(State FE, Yes, ///
														    Survey Year FE, Yes, ///
														    State FE x Survey Year FE, No, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 

//Column 6															
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize trust_others
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc, absorb(birth_state_gen scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d4.doc, append dec(3) nocons addtext(State FE, No, ///
														    Survey Year FE, No, ///
														    State FE x Survey Year FE, Yes, ///
															Birth State FE x Generation FE, Yes) keep(zwgrowth_rate_1) 	

//--------------------------------------------------------
//Create Table D5
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_fed_govt wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, replace dec(3) nocons addtext(State FE, Yes, ///
													   Survey Year FE, Yes, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, No) keep(zwgrowth_rate_1 zincumbent_partisan) 																	

//Column 2													   
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_fed_govt wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, append dec(3) nocons addtext(State FE, No, ///
													   Survey Year FE, No, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1 zincumbent_partisan) 																	

//Column 3													   
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_govt_index wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, append dec(3) nocons addtext(State FE, Yes, ///
													   Survey Year FE, Yes, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, No) keep(zwgrowth_rate_1 zincumbent_partisan) 																	

//Column 4													   
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_govt_index wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, append dec(3) nocons addtext(State FE, No, ///
													   Survey Year FE, No, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1 zincumbent_partisan) 	

//Column 5													   
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_others wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, append dec(3) nocons addtext(State FE, Yes, ///
													   Survey Year FE, Yes, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, No) keep(zwgrowth_rate_1 zincumbent_partisan) 		

//Column 6													   
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc incumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
cap drop z*
local varlist trust_others wgrowth_rate_1 yob_ln_gdppc incumbent_partisan
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc zincumbent_partisan, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_d5.doc, append dec(3) nocons addtext(State FE, No, ///
													   Survey Year FE, No, ///
													   Generation FE, Yes, ///
													   State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1 zincumbent_partisan)
